﻿using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.AspNetCore.Mvc;
using MyBookStore.Application;
using Volo.Abp.Autofac;

namespace MyBookStore.Web
{
    [DependsOn(typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), typeof(MyBookStoreApplicationModule))]
    public class MyBookStoreWebModule : AbpModule
    {
        /// <summary>
        /// 承接依赖注入里的内容
        /// </summary>
        /// <param name="context"></param>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;
            services.AddSingleton<IUserService, UserService>();//单例类
            //services.AddScoped<IUserAppService, UserAppService>();//作用域模式
            services.AddControllersWithViews();
        }

        /// <summary>
        /// 承接中间件里的内容
        /// </summary>
        /// <param name="context"></param>
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();
            // Configure the HTTP request pipeline.
            if (!env.IsDevelopment())
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                // 配置控制器路由
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            //app.Run();
        }
    }
}
